package com.hy.mydesktop.client.mvc.core.builder;

import java.util.HashMap;
import java.util.Map;

import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;

public class WindowBuilderTemplate {

	public static GxtComponentControllerMetaNodeModel createWindowTemplate(Map<String, Object> map1,Map<String, Object> map2) {
		//窗口+表格
		Map<String , Object> windowController=new HashMap<String, Object>();
		windowController.put(MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE, ComponentControllerEnum.WINDOW_CONTROLLER_MODEL);
		windowController.put(MetaDataConstants.COMPONENT_CONTROLLER_MODEL_TYPE_INDEX, ComponentControllerEnum.WINDOW_CONTROLLER_MODEL.ordinal());
		//List<String> codes1 = new ArrayList<String>();
		//codes1.add("0301");				
		//windowController.put("registereventtypes", codes1);
		//windowController.put("viewdata", "window_viewData_init_01");		
		//windowController.put("id", "1_1_windowController_PositonType");
		/*for (String key : map1.keySet()) {
			windowController.put(key, map1.get(key));
		}*/
		
		GxtComponentControllerMetaNodeModel node=new GxtComponentControllerMetaNodeModel(windowController);	
		node = ControllerAndComponentMetaNodeModelCreationTemplate.buildCommonAttributes(node,map1);
		if (map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
			String controllerMetaModelId=(String)map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
			String id="windowController_"+controllerMetaModelId;
			node.setId(id);
			node.setControllerMetaNodeModelId(id);
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		
		map2.put(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, (String)map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID));
		//node.setRegisterEventTypes(node.addGxtAppEventType("0301"));
		GxtComponentMetaNodeModel gxtComponentMetaNodeModel =getWindowGxtComponentMetaNodeModel(map2);
		//windowController.put(MetaDataConstants.GXT_COMPONENT__METANODEMODEL, getWindowGxtComponentMetaNodeModel());
		node.setGxtComponentMetaNodeModel(gxtComponentMetaNodeModel);
		
		
		return node;
		
	}
	
	

	public static GxtComponentMetaNodeModel getWindowGxtComponentMetaNodeModel(Map<String, Object> map2 ) {
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("component_model_type", ComponentTypeEnum.WINDOW_MODEL);
		map.put("component_model_type_index", ComponentTypeEnum.WINDOW_MODEL.ordinal());
		//map2.put("title", "职位类型设置");
		//map2.put("heading", "职位类型设置");
		map.put("width", 800);
		map.put("height", 550);
		//map2.put("id", "01_01_windowGxtComponent_PositonType");
		map.put("resizable", false);
		map.put("maxmizable", false);
		map.put("minmizable", true);
		map.put(ComponentMetaDataConstants.LAYOUT_INDEX, ComponentTypeEnum.FITLAYOUT_MODEL.ordinal());
		for (String key : map2.keySet()) {
			map.put(key, map2.get(key));
		}
		GxtComponentMetaNodeModel gxtComponentMetaNodeModel=new GxtComponentMetaNodeModel(map);
		//gxtComponentMetaNodeModel.setTitle(map2.get(ComponentMetaDataConstants.TITLE).toString());
		//gxtComponentMetaNodeModel.set(ComponentMetaDataConstants.HEADING, 
		//		map2.get(ComponentMetaDataConstants.HEADING).toString());
		if (map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
			String controllerMetaModelId=(String)map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
			String id="windowGxtComponent_"+controllerMetaModelId;
			gxtComponentMetaNodeModel.setId(id);
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		gxtComponentMetaNodeModel =ControllerAndComponentMetaNodeModelCreationTemplate.removeUnusedProperties(gxtComponentMetaNodeModel);
		return gxtComponentMetaNodeModel;
		
	}



	

}
